package com.pollux.handler;

import com.pollux.constant.MessageConstant;
import com.pollux.exception.BaseException;
import com.pollux.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: pollux
 * @CreateTime: 2024-10-31
 * @Description: 全局异常处理类
 * @Version: 1.0
 */

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * @param BaseException 自定义异常基类
     * @description: 自定义异常处理
     * @author: pollux
     * @date: 2024/10/31 13:23
     */
    @ExceptionHandler
    public Result<String> handleException(BaseException e) {
        log.error("自定义业务异常捕捉:{}",e.getMessage());
        return Result.error(e.getMessage());
    }



    /**
     * @param Exception 所有异常的基类
     * @description: 出现了位置不预料的异常，统一返回未知错误
     * @author: pollux
     * @date: 2024/10/31 13:24
     */
    @ExceptionHandler
    public Result<String> handleException(Exception e) {
        log.error("系统异常捕捉:{}",e.getMessage());

        return Result.error(MessageConstant.UNKNOT_ERROR);
    }
}






















